package logic
{	
	import Sync.*;
	
	import entity.EntityManager;
	
	import flash.utils.*;
	
	public class GameLogic 
	{
		private static var s_ins:GameLogic = null;
		private var m_selfPlayerHandleID:int = -1;
		private var m_isHost:int = 0;
		private var m_pong:Boolean = true;
		private var m_pingTime:int = 0;
		private var m_pingValue:int = 0;
		private var m_playerCount:int = 0;
		
		public function GameLogic()
		{

		}
		
		public static function getInstance():GameLogic
		{
			if (s_ins == null)
			{
				s_ins = new GameLogic();
			}
			
			return s_ins;
		}		
		
		public function initalize():void
		{

		}
		
		public function release():void
		{
			
		}
		
		public function logicStep(frameTime:int):void
		{
			EntityManager.getInstance().logicStep(frameTime);
		}
		
		public function setSelfPlayerHandleID(id:int):void
		{
			m_selfPlayerHandleID = id;
		}
		
		public function getSelfPlayerHandleID():int
		{
			return m_selfPlayerHandleID;
		}
		
		public function setIsHost(host:int):void
		{
			m_isHost = host;
		}
		
		public function getIsHost():int
		{
			return m_isHost;
		}
		
		public function ping():void
		{
			if (m_pong)
			{
				m_pong = false;
				
				var syncSys:SyncSystem = SyncSystem.getInstance();
				
				syncSys.beginSendMsg(ConstValue.MSG_ID_PING);
				syncSys.endSendMsg();

				m_pingTime = getTimer();
			}
		}
		
		public function pong():void
		{
			m_pong = true;
			m_pingValue = getTimer() - m_pingTime;
		}
		
		public function getPingValue():int
		{
			return m_pingValue;
		}
		
		public function setPlayerCount(count:int):void
		{
			m_playerCount = count;
		}
		
		public function getPlayerCount():int
		{
			return m_playerCount;
		}
	}
}